//
//  ChooseImagePickSourceTypeController.m
//  ox
//
//  Created by 喻杰 on 2016/10/29.
//  Copyright © 2016年 fengge. All rights reserved.
//

#import  "ChooseImagePickSourceTypeController.h"


@interface ChooseImagePickSourceTypeController()
    @property(nonatomic,strong) UIView * up;
    @property(nonatomic,strong) UIView * down;
@end

@implementation ChooseImagePickSourceTypeController


@synthesize up,down,showPickView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor  = [UIColor clearColor];
    self.view.alpha = 1;
  
    UIButton * btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.backgroundColor = [UIColor whiteColor];
    [btn setTitle:@"拍照" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(tickPicture:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag =1;

    UIButton * btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn1.backgroundColor = [UIColor whiteColor];
    btn1.titleLabel.textColor = [UIColor blackColor];
    [btn1 setTitle:@"从手机相册选择" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn1.tag =2;
    [btn1 addTarget:self action:@selector(tickPicture:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton * btn2 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn2.backgroundColor = [UIColor whiteColor];
    btn2.titleLabel.textColor = [UIColor blackColor];
    [btn2 setTitle:@"取消" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn2.tag =3;
    [btn2 addTarget:self action:@selector(tickPicture:) forControlEvents:UIControlEventTouchUpInside];

    up =[[UIView alloc]init];
    up.backgroundColor =[UIColor blackColor];
    up.alpha = 0.6;
    
    down =[[UIView alloc]init];
    down.backgroundColor = [[UIColor alloc]initWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:0.95];
    down.alpha = 1;
    
    [down addSubview:btn];
    
    [down addSubview:btn1];
    
    [down addSubview:btn2];
    
    [self.view addSubview:up];
    
    [self.view addSubview:down];
    
    [up mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, -201, 0));
    }];
    [down mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        make.bottom.mas_equalTo(self.view).with.offset(201);
        make.height.mas_equalTo(201);
    }];
    btn2.titleLabel.font = [UIFont systemFontOfSize:[UIFont buttonFontSize]];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(down).with.offset(0);
        make.right.mas_equalTo(down).with.offset(0);
        make.bottom.mas_equalTo(down).with.offset(0);
        make.height.mas_equalTo(60);
    }];
    btn1.titleLabel.font = [UIFont systemFontOfSize:[UIFont buttonFontSize]];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(down).with.offset(0);
        make.right.mas_equalTo(down).with.offset(0);
        make.top.mas_equalTo(btn).with.offset(61);
        make.height.mas_equalTo(60);
    }];
    btn.titleLabel.font = [UIFont systemFontOfSize:[UIFont buttonFontSize]];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(down).with.offset(0);
        make.right.mas_equalTo(down).with.offset(0);
        make.top.mas_equalTo(down).with.offset(0);
        make.height.mas_equalTo(60);
    }];
}

-(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self dismissViewControllerAnimated:NO completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void) tickPicture:(UIButton *)sender{
    if(sender.tag == 3){
        [self dismissViewControllerAnimated:NO completion:nil];
        return;
    }
    [self dismissViewControllerAnimated:NO completion:nil];
    self.showPickView(sender);
}

- (void)viewDidAppear:(BOOL)animated{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    down.frame = CGRectMake(0, self.view.bounds.size.height-201, self.view.bounds.size.width, 201);
    [UIView commitAnimations];
}




@end
